package com.powergisol.gis.geom;



import com.powergisol.core.math.Dot;
import com.vividsolutions.jts.geom.Coordinate;

import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.io.WKTWriter;





public class GeoPoint extends GeoType {

    private Coordinate coordinate;

    private double[] points;


    public GeoPoint(Coordinate coordinate) {
        this.coordinate = coordinate;
    }

    public GeoPoint(double x, double y) {
        coordinate = new Coordinate(x,y);
    }


    public GeoPoint(double x, double y, double z) {
        this(x,y);
        this.coordinate.z = z;
    }


    public GeoPoint(double[] points) {

        if(points.length<2||points.length>3){
            throw new RuntimeException("点坐标只能有X,Y,Z 中的两个或者三个");
        }

        coordinate = new Coordinate(points[0],points[1]);
        if(points.length==3){
            this.coordinate.z = points[2];
        }
    }

    public double getX(){
        return coordinate.x;
    }

    public double getY(){
        return coordinate.y;
    }


    public double getZ(){
        return coordinate.z;
    }

    @Override
    public String toWKT() {
        return WKTWriter.toPoint(coordinate);
    }



    @Override
    public Point toGeometry(){
        return geometryFactory.createPoint( this.coordinate );
    }

    public double[] getPoints() {
        points = new double[]{coordinate.x,coordinate.y,coordinate.z};
        return points;
    }

    @Override
    public String toString() {
        return "GeoPoint{" +
                "coordinate=" + coordinate +
                ", properties=" + properties +
                '}';
    }

    /**
     * 转换成空间解析几何的点
     * @return
     */
    public Dot toDot(){
        return new Dot(getX(),getY(),getZ());
    }
}
